<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>平台快速开通</title>
    <#include "/header.html">
    <link
            href="${request.contextPath}/statics/plugins/jquery-layout/jquery.layout-latest.css"
            rel="stylesheet" />
    <link
            href="${request.contextPath}/statics/css/bootstrapZtree.css"
            rel="stylesheet" />
    <style>
        input[type="radio"] + label::before {
            content: "\a0"; /*不换行空格*/
            display: inline-block;
            vertical-align: middle;
            font-size: 18px;
            width: 1em;
            height: 1em;
            margin-right: .4em;
            border-radius: 50%;
            border: 1px solid #1c84c6;
            text-indent: .15em;
            line-height: 1;
        }
        input[type="radio"]:checked + label::before {
            background-color: #1c84c6;
            background-clip: content-box;
            padding: .2em;
        }
        input[type="radio"] {
            position: absolute;
            clip: rect(0, 0, 0, 0);
        }
        .texts{
            white-space: normal !important;
            height:auto;
            vertical-align:text-top;
            word-break: break-all;
            white-space: pre-line !important;
            overflow: visible !important;
            padding:5px;
        }
        .selectedTr{
            background-color: #dff0d8 !important;
        }
        .selectedTr td{
            background-color: #dff0d8 !important;
        }
    </style>
</head>
<body>
<div id="rrapp" class="container-div ui-layout-center" style="background-color: #fff">
   <div v-show="showList=='step4'" class="panel panel-default">
        <div class="panel-heading">平台信息配置 step4 > 三方数据选择</div>
        <form class="form-horizontal" id="formBtnSelect2" style="width: 660px;">
            <div class="form-group">
                <div class="col-sm-2 control-label">第三方平台</div>
                <div class="col-sm-10">
                    <select class="selectpicker" id="thirdOs" data-live-search="true">
                        <option value="">请选择第三方平台</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">第三方渠道</div>
                <div class="col-sm-10">
                    <select class="selectpicker" id="thirdChannel" data-live-search="true">
                        <option value="">请选择第三方渠道</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label"></div>
                <input type="button" ref="submitBtn" class="btn btn-primary" @click="bindThirdData()" value="下一步"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="backPreStep(3)" value="上一步"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-info"  @click="stepPass(5)" value="跳过"/>
            </div>
        </form>
    </div>

    <div v-show="showList=='step5'" class="panel panel-default">
        <div class="panel-heading">平台信息配置 step5 > 用户模块</div>
        <form class="form-horizontal" id="formBtn" style="width: 660px;">
            <div class="form-group">
                <div class="col-sm-2 control-label">平台选择</div>
                <div class="col-sm-10">
                    <select class="selectpicker" id="platformId" data-actions-box="true" data-select-all-text="全选" data-deselect-all-text="取消全选" multiple title="请选择平台名称"   style="width:100%;" >

                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">操作按钮</div>
                <div class="col-sm-10">
                <input type="button" class="layui-btn" @click="createUserTb()" id="userBtn3" ref="userBtn3" value="创建用户表"/>
                &nbsp;&nbsp;<input type="button" class="layui-btn layui-btn-normal" @click="userInitData()" id="userBtn1" ref="userBtn1" value="初始化数据配置"/>
                &nbsp;&nbsp;<input type="button" class="layui-btn layui-btn-danger" id="userBtn2" @click="saveUserScheduleJob()" ref="userBtn2" value="创建用户定时任务"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label"></div>
                <input type="button" ref="submitBtn" class="btn btn-primary" @click="stepPass(6)" value="下一步"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="backPreStep(4)" value="上一步"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-info"  @click="stepPass(6)" value="跳过"/>
            </div>
        </form>
    </div>

    <div v-show="showList=='step6'" class="panel panel-default">
      <div class="panel-heading">平台信息配置 step6 > 文章模块</div>
         <form class="form-horizontal" id="form9" style="width: 660px;">
             <div class="form-group">
                 <div class="col-sm-2 control-label">平台选择</div>
                 <div class="col-sm-10">
                     <select class="selectpicker" id="artPlatform" data-actions-box="true" data-select-all-text="全选" data-deselect-all-text="取消全选" multiple title="请选择平台名称"   style="width:100%;" >

                     </select>
                 </div>
             </div>
             <div class="form-group">
                 <div class="col-sm-2 control-label">操作按钮</div>
                 <input type="button" class="layui-btn" id="articleBtn0" ref="articleBtn0" @click="createArticleTab()" value="创建文章表"/>
                 &nbsp;&nbsp;<input type="button" class="layui-btn layui-btn-normal" @click="initArticleData()" ref="articleBtn1" id="articleBtn1" value="初始化数据配置"/>
                 &nbsp;&nbsp;<input type="button" class="layui-btn layui-btn-danger" @click="createArticleTimer()" ref="articleBtn2" id="articleBtn2" value="创建文章定时任务"/>
             </div>
             <div class="form-group">
                 <div class="col-sm-2 control-label"></div>
                 <input type="button" ref="submitBtn" class="btn btn-primary" @click="stepPass(7)" value="下一步"/>
                 &nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="backPreStep(5)" value="上一步"/>
                 &nbsp;&nbsp;<input type="button" class="btn btn-info" @click="stepPass(7)" value="跳过"/>
             </div>
         </form>
    </div>
    <div v-show="showList=='step7'" class="panel panel-default">
        <div class="panel-heading">平台信息配置 step7 > 域名模块</div>
        <form class="form-horizontal" id="formBtn2" style="width: 660px;">
            <div class="form-group">
                <div class="col-sm-2 control-label">平台选择</div>
                <div class="col-sm-10">
                    <select class="selectpicker" id="domainPlatform" data-actions-box="true" data-select-all-text="全选" data-deselect-all-text="取消全选" multiple title="请选择平台名称"   style="width:100%;" >

                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">操作按钮</div>
                <input type="button" class="layui-btn" @click="createDomainTab()" id="domainBtn0" ref="domainBtn0" value="创建域名表"/>
                &nbsp;&nbsp;<input type="button" class="layui-btn layui-btn-danger" @click="createDomainTimer()" id="domainBtn1" ref="domainBtn1" value="创建域名定时任务"/>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label"></div>
                <input type="button" ref="submitBtn" class="btn btn-primary" @click="saveStep4()" value="完成"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-warning"  @click="backPreStep(6)" value="上一步"/>
            </div>
        </form>
    </div>

<div v-show="showList=='step3'" class="panel panel-default">
    <div class="panel-heading">平台信息配置 step3 > 配置平台信息</div>
    <form class="form-horizontal" id="form">
        <div class="form-group">
            <div class="col-sm-2 control-label">平台名称</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" v-model="step1.platformName" placeholder="平台名称"/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">平台昵称</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" v-model="step1.nickName" placeholder="平台昵称"/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">选择数据源</div>
            <div class="col-sm-10">
                <select class="selectpicker" id="dataSource" data-live-search="true"></select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">选择站点</div>
            <div class="col-sm-10">
                <select class="selectpicker" id="siteSelect" multiple  data-live-search="true">

                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">排序号</div>
            <div class="col-sm-10">
                <input type="number" class="form-control" v-model="step1.sort" placeholder="排序号"/>
            </div>
        </div>
       <div class="form-group">
            <div class="col-sm-2 control-label"></div>
            <input type="button" ref="submitBtn" class="btn btn-primary" @click="saveStep1" value="下一步"/>
            &nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="backPreStep(2)" value="上一步"/>
           &nbsp;&nbsp;<input type="button" class="btn btn-info" @click="stepPass(4)" value="跳过"/>
        </div>
    </form>

</div>
    <div v-show="showList=='step1'" class="panel panel-default">
           <div class="panel-heading">平台信息配置 step1 > 配置数据源</div>
          <form class="form-horizontal" id="form2">
            <div class="form-group">
                <div class="col-sm-2 control-label">数据源名称</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="step2.sourceName"
                           placeholder="数据源名称">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">用户名</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="step2.username"
                           placeholder="用户名">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">密码</div>
                <div class="col-sm-10">
                    <input type="password" class="form-control" v-model="step2.password"
                           placeholder="密码">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">数据库地址</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="step2.dbUrl"
                           placeholder="数据库地址">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label">数据库名称</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="step2.dbName"
                           placeholder="数据库名称">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label"></div>
                <input type="button" ref="submitBtn" class="btn btn-primary" @click="saveStep2" value="下一步"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="backPreStep(1)" value="上一步"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-info" @click="stepPass(2)" value="跳过"/>
            </div>
        </form>
 </div>

    <div v-show="showList=='step2'" class="panel panel-default">
        <div class="panel-heading">平台信息配置 step2 > 配置站点类型</div>
        <form class="" id="form4">
            <div>
                 <div class="grid-btn">
                    <div class="form-group col-sm-2">
                        <input type="text" class="form-control" v-model="q.cateName"
                               placeholder="类型名称">
                    </div>
                    <a class="btn btn-default" @click="query">查询</a>
             </div>
            <div class="form-group">
                <div class="col-sm-12 select-info table-striped">
                    <table id="bootstrap-table1" data-mobile-responsive="true"></table>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 control-label"></div>
                <input type="button" ref="submitBtn" class="btn btn-primary" @click="saveStep3" value="下一步"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="backPreStep(1)" value="上一步"/>
                &nbsp;&nbsp;<input type="button" class="btn btn-info" @click="stepPass(3)" value="跳过"/>
            </div>
            </div>
        </form>
    </div>
</div>

<script src="${request.contextPath}/statics/plugins/jquery-layout/jquery.layout-latest.js"></script>
<script src="${request.contextPath}/statics/js/zTreeCore.js"></script>
<script src="${request.contextPath}/statics/js/zTreeEdit.js"></script>
<script src="${request.contextPath}/statics/js/zTreeExcheck.js"></script>
<script src="${request.contextPath}/statics/plugins/layui/layui.all.js"></script>
<script>
$(document).ready(function () {
    $('body').layout({
        west__size : 185
    });
    //注意：选项卡 依赖 element 模块，否则无法进行功能性操作
    layui.use(['element','form'], function(){
        var element = layui.element;
        element.on('tab(docDemoTabBrief)', function(data){
            console.log(data.index);
            // vm.nav_tabs = data.index==0?2:1;
            // vm.query();
        });
    });
    $("#siteSelect").selectpicker({
        noneSelectedText: '请选择',
        countSelectedText: function(){}
    });
    $("#dataSource").selectpicker({
        noneSelectedText: '请选择',
        countSelectedText: function(){}
    });
    $("#thirdOs").selectpicker({
        noneSelectedText: '请选择',
        countSelectedText: function(){}
    });
    $("#thirdChannel").selectpicker({
        noneSelectedText: '请选择',
        countSelectedText: function(){}
    });
    vm.changeSelect();
    vm.reload();
    vm.resetFrom();
    $('#bootstrap-table1')
        .bootstrapTable(
            {
                method : 'post', // 服务器数据的请求方式 get or post
                contentType : "application/json",
                url : baseURL + 'baiducategory/findBaiduCategoryPage', // 服务器数据的加载地址
                showRefresh : true,
                showToggle : true,
                showColumns : true,
                //showExport :true,
                sortable: true,
                sortName:"userId",// 排序列名称
                sortOrder: "desc",
                iconSize : 'outline',
                toolbar : '#exampleToolbar',
                striped : true, // 设置为true会有隔行变色效果
                dataType : "json", // 服务器返回的数据类型
                pagination : true, // 设置为true会在底部显示分页条
                // queryParamsType : "limit",
                // //设置为limit则会发送符合RESTFull格式的参数
                singleSelect : false, // 设置为true将禁止多选
                // contentType : "application/x-www-form-urlencoded",
                // //发送到服务器的数据编码类型
                pageSize : 10, // 如果设置了分页，每页数据条数
                pageNumber : 1, // 如果设置了分布，首页页码
                // search : true, // 是否显示搜索框
                //showColumns : false, // 是否显示内容下拉框（选择显示的列）
                sidePagination : "server", // 设置在哪里进行分页，可选值为"client" 或者
                // "server"
                queryParams : function(params) {
                    //console.log(params)
                    return {
                        // 说明：传入后台的参数包括offset开始索引，limit步长，sort排序列，order：desc或者,以及所有列的键值对
                        limit : params.limit,
                        page : (params.offset/params.limit) + 1,
                        cateName : vm.q.cateName,
                     };
                },
                columns : [
                    {
                        field : 'cateName',
                        align:'center',
                        title : '类型名称'
                    },
                    {
                        field : 'cateKey',
                        align:'center',
                        title : '类型KEY'
                    },
                    {
                        title : '操作',
                        field : 'id',
                        width:330,
                        align : 'center',
                        formatter : function(
                            value, row,
                            index) {
                             var f = '<a class="btn btn-success btn-sm '
                                + ''
                                + '" href="#" title="绑定"  mce_href="#" onclick="bindSite(\''
                                + row.id
                                + '\')"><i class="fa fa-wrench" style="margin-right: 5px"></i>绑定</a> ';
                            return f;
                        }
                    } ]
            });
    $('#bootstrap-table')
        .bootstrapTable(
            {
                method : 'post', // 服务器数据的请求方式 get or post
                url : baseURL + 'platformjob/findPlatformJobPage', // 服务器数据的加载地址
                showRefresh : true,
                showToggle : true,
                showColumns : true,
                //showExport :true,
                sortable: true,
                sortName:"userId",// 排序列名称
                sortOrder: "desc",
                iconSize : 'outline',
                toolbar : '#exampleToolbar',
                striped : true, // 设置为true会有隔行变色效果
                dataType : "json", // 服务器返回的数据类型
                pagination : true, // 设置为true会在底部显示分页条
                // queryParamsType : "limit",
                // //设置为limit则会发送符合RESTFull格式的参数
                singleSelect : false, // 设置为true将禁止多选
                // contentType : "application/x-www-form-urlencoded",
                // //发送到服务器的数据编码类型
                pageSize : 10, // 如果设置了分页，每页数据条数
                pageNumber : 1, // 如果设置了分布，首页页码
                // search : true, // 是否显示搜索框
                //showColumns : false, // 是否显示内容下拉框（选择显示的列）
                sidePagination : "server", // 设置在哪里进行分页，可选值为"client" 或者
                // "server"
                queryParams : function(params) {
                    //console.log(params)
                    return {
                        // 说明：传入后台的参数包括offset开始索引，limit步长，sort排序列，order：desc或者,以及所有列的键值对
                        page:(params.offset/params.limit) + 1,
                        limit:params.limit,
                        jobType:vm.nav_tabs,
                        beanName:vm.q.beanName
                       };
                },
                complete:function () {
                    $('[data-toggle="tooltip"]').tooltip({
                        html:true
                    });
                },
                onLoadSuccess:function () {
                    $('[data-toggle="tooltip"]').tooltip({
                        html:true
                    });
                },
                columns : [
                    {
                        checkbox : true
                    },
                    {
                        field : 'id',
                        align:'center',
                        title : '任务ID'
                    },
                    {
                        field : 'beanName', // 列字段名
                        align:'center',
                        title : 'bean名称',// 列标题
                    },
                    {
                        field : 'methodName',
                        align:'center',
                        width:200,
                        title : '方法名称'
                    },
                    {
                        field : 'intervalSeconds',
                        align:'center',
                        title : '时间间隔'
                    },
                    {
                        field : 'beginDate',
                        align:'center',
                        width:200,
                        title : '开始时间'
                    },
                    {
                        field : 'endDate',
                        align:'center',
                        width:200,
                        title : '结束时间'
                    },
                    {
                        field : 'platformName',
                        align:'center',
                        title : '使用平台',
                        formatter: function(value, options, row){
                            // console.log(value[1])
                            var str = '';
                            value.map(function (item) {
                                str = str + item + '<br />';
                            });
                            //console.log(str)
                            var toolTips = '<i data-toggle="tooltip" data-placement="top" title="'+str+'">'+value.length+'</i>'
                            return toolTips;
                        }
                    },
                    {
                        field : 'cronExpression',
                        title : 'cron表达式',
                        align:'center',
                        width:200,
                        titleTooltip: "this is name"
                    },
                    {
                        field : 'remark',
                        align:'center',
                        title : '备注'
                    },
                    {
                        field : 'status',
                        align:'center',
                        title : '状态',
                        formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-success">正常</span>' :
                                '<span class="label label-danger">暂停</span>';
                        }
                    }]
            });
    $('#bootstrap-table').on('click-row.bs.table', function (e, row, element)
      {
        $(element).find("input").click();
        if($(element).hasClass("selected")){
            $(element).addClass("selectedTr");
        }else{
            $(element).removeClass("selectedTr");
        }
    });
});
var setting = {
    data:{
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "accountId",
            rootPId: -1
        }
    },

    view: {
        // addHoverDom: addHoverDom,
        // removeHoverDom: removeHoverDom,
        selectedMulti: false
    },
    check: {
        enable: true,
        chkStyle : "checkbox",    //复选框
        chkboxType : {
            "Y" : "ps",
            "N" : "ps"
        }
    },
    callback : {
        beforeClick : beforeClick,
        onCheck : onCheck
    }
};
var ztree;
function beforeClick(treeId, treeNode) {
    var zTree = $.fn.zTree.getZTreeObj("siteType");
    zTree.checkNode(treeNode, !treeNode.checked, null, true);
    return false;
};
function onCheck(e, treeId, treeNode) {
    var zTree = $.fn.zTree.getZTreeObj("siteType");
    var nodes = zTree.getCheckedNodes(true);
    //console.log(nodes)
    vm.checkNode = [];
    for (var i = 0, l = nodes.length; i < l; i++) {
        if (!nodes[i].isParent) {       //isParent判断是否为父级，也就是是否有下级
            vm.checkNode.push(nodes[i].id);    //获取所选节点的名称
        }
    }

};
var vm = new Vue({
    el : '#rrapp',
    data : {
        q : {
            platformName : null,
            beanName: null,
            cateName:null
        },
        showPlatformTimer:true,
        showList : "step1",
        isReadOnly:null,
        platformId:null,
        allSite:[],
        checkNode:[],
        schedule: {},
        nav_tabs:2,
        cateId:null,
        param:{
            platformId:null
        },
        step1 : {
            platformName:'',
            dataSourceId:'',
            thirdpartyPlatformId:'',
            nickName:'',
            sort:''
        },
        step2:{
            sourceName:'',
            username:'',
            password:'',
            dbUrl:'',
            dbName:''
        },
        step3:{
            cateName:'',
            queryFiled:'',
            cateKey:''
        }
    },
   methods : {
        reload : function() {
            vm.showList = 'step1';
            vm.step1 = {
                platformName:'',
                // dataSourceId:'',
                // thirdpartyPlatformId:'',
                nickName:'',
                sort:''
            };
            vm.step2 = {
                sourceName:'',
                username:'',
                password:'',
                dbUrl:'',
                dbName:''
            };
            vm.step3 = {
                cateName:'',
                queryFiled:'',
                cateKey:''
            };
            vm.getDataSource();
            vm.getAllSite();
            vm.getSiteType();
            vm.getThirdOs();
            vm.getThirdChannel();
            vm.getAllPlatform();
            // console.log(vm.showList);
        },
       query:function () {
           vm.getSiteType();
       },
       queryPlatform:function () {
           vm.showPlatformTimer = true;
           vm.getPlatformTimer();
       },
       getAllPlatform:function () {
           $.ajax({
               type: "get",
               url: baseURL + "platform/findAllPlatform",
               dataType: "json",
               success: function (data) {
                   if (data.code == 0) {
                       var _html = ''
                       for (var i = 0; i < data.platformList.length; i++) {
                           _html = _html + '<option value="' + data.platformList[i].platformId + '">' + data.platformList[i].platformName + '</option>'
                       }
                       $('#platformId').html(_html);
                       $('#platformId').selectpicker('refresh');
                       $('#artPlatform').html(_html);
                       $('#artPlatform').selectpicker('refresh');
                       $('#domainPlatform').html(_html);
                       $('#domainPlatform').selectpicker('refresh');
                   }
               }
           });
       },
       resetFrom:function () {
           $('#timerSite').selectpicker('val', '');
           $('#timerSite').selectpicker('refresh');
           vm.schedule.platformName = [];
           layui.use('laydate', function(){
               var laydate = layui.laydate;
               //日期时间范围
               laydate.render({
                   elem: '#test10'
                   ,type: 'datetime'
                   ,range: true,
                   value:'',
                   done:function (value,date) {
                       // console.log(value);
                       // console.log(date);
                       var splitDate = value.split(' - ');
                       vm.schedule.beginDate = splitDate[0];
                       vm.schedule.endDate = splitDate[1];
                       //console.log(splitDate);
                   }
               });
           });
           vm.getTimerAllSite();
           vm.changeSelect();
       },
       getThirdChannel:function () {
           $("#thirdChannel").find(".addOption3").remove();
           $.ajax({
               type : "GET",
               async: false,
               url : baseURL + "platformChannel/findAllThirdpartyChannel",
               data:{},
               contentType : "application/json",
               success : function(r) {
                   if (r.code === 0) {
                       var str = '';
                       r.result.map(function (item) {
                           str = str + '<option class="addOption3" value="'+ item.channelId +'">' + item.channelName + '</option>';
                       });
                       $("#thirdChannel").append(str);
                       $('#thirdChannel').selectpicker('refresh');
                   } else {
                       alert(r.msg);
                   }
               }
           });
       },
       getSiteType:function () {
           var opt = {
               url: baseURL + 'baiducategory/findBaiduCategoryPage',
               contentType : "application/json",
               silent: true,
               query:{
                   limit : 10,
                   page : 1,
                   cateName : vm.q.cateName
               }
           };

           $('#bootstrap-table1').bootstrapTable('refresh',
               opt);
       },
       getPlatformTimer:function () {
           var opt = {
               url: baseURL + 'platformjob/findPlatformJobPage',
               query:{
                   limit : 10,
                   page : 0,
                   jobType:vm.nav_tabs,
                   beanName:vm.q.beanName
               }
           };
           $('#bootstrap-table').bootstrapTable('refresh',
               opt);
          // console.log(2222)
       },
        getAllSite:function () {
            $("#siteSelect").find(".addOption").remove();
            $.ajax({
                type : "POST",
                url : baseURL + "ip/findBindSiteList",
                contentType : "application/json",
                data:JSON.stringify({platformId:null}),
                success : function(r) {
                    if (r.code === 0) {
                        vm.allSite = r.result;
                        var str = '';
                        for(var i=0;i<r.result.cateList.length;i++){
                            str = str + '<optgroup label="'+r.result.cateList[i].name+'">';
                            for(var j=0;j<r.result.cateList[i].siteList.length;j++){
                                str = str + '<option class="addOption" value="'+ r.result.cateList[i].siteList[j].id +'">'
                                    + r.result.cateList[i].siteList[j].name + '</option>';
                            }
                            str = str + '</optgroup>'
                        }
                        //console.log(str)
                        $("#siteSelect").append(str);
                        $('#siteSelect').selectpicker('refresh');
                        if(r.result.bindList.length>0){
                            $('#siteSelect').selectpicker('val',r.result.bindList);
                            $('#siteSelect').selectpicker('refresh');
                        }
                        vm.displaySelect();
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
       updatePlatform: function () {
           var jobId = getSelectedRow();
           // console.log(jobId);
           if(jobId == null){
               return ;
           }
           vm.schedule.platformName = [];
           $.ajax({
               type: "POST",
               url: baseURL + 'platformjob/findPlatformJobById',
               contentType: "application/json",
               data: JSON.stringify({id:jobId.id}),
               success: function(r){
                   if(r.code === 0){
                       vm.showPlatformTimer = false;
                       vm.title = "修改";
                       vm.schedule = r.result;
                       vm.isReadOnly = "readonly";
                       vm.schedule.id = r.result.id;
                       var i = r.result.jobType==2?0:1;
                       $('#radios :radio').removeAttr('checked');
                       $('#radios :radio').eq(i).prop('checked','checked');
                       $('#timerSite').selectpicker('val', r.result.platformId);
                       $('#timerSite').selectpicker('refresh');
                       if(r.result.beginDate && r.result.endDate){
                           layui.use('laydate', function(){
                               var laydate = layui.laydate;
                               //日期时间范围
                               laydate.render({
                                   elem: '#test10'
                                   ,value:r.result.beginDate + ' - ' + r.result.endDate
                               });
                           });
                       }else{
                           $('#test10').val('');
                       }

                   }else{
                       alert(r.msg);
                   }
               }
           });
       },
       updateTimer:function () {
           var url =  "platformjob/updatePlatformJob";
           vm.schedule.jobType = $('input[name="type"]:checked').val();
           vm.schedule.firstStart = $('input[name="start"]:checked').val()==2?true:false;
           //console.log(vm.schedule)
           if(checkIsBank(vm.schedule.beanName) || checkIsBank(vm.schedule.platformId) || checkIsBank(vm.schedule.platformName)
               || checkIsBank(vm.schedule.methodName) || checkIsBank(vm.schedule.cronExpression)){
               alert('有*的为必填字符，请完整输入');
               return;
           }
          $.ajax({
               type: "POST",
               url: baseURL + url,
               contentType: "application/json",
               data: JSON.stringify(vm.schedule),
               success: function(r){
                    if(r.code === 0){
                       alert('操作成功', function() {
                           vm.queryPlatform();
                       });
                   }else{
                       alert(r.msg);
                   }
               }
           });
       },
        getDataSource:function () {
            $("#dataSource").find(".addOption2").remove();
            $.ajax({
                type : "POST",
                url : baseURL + "dataSource/findDataSourceList",
                async: false,
                data:{},
                contentType : "application/json",
                success : function(r) {
                    if (r.code === 0) {
                        var str = '';
                        r.result.map(function (item) {
                            str = str + '<option class="addOption2" value="'+ item.id +'">' + item.sourceName + '</option>';
                        });
                        $("#dataSource").append(str);
                        $('#dataSource').selectpicker('refresh');
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
       getThirdOs:function () {
           $("#thirdOs").find(".addOption3").remove();
           $.ajax({
               type : "GET",
               url : baseURL + "thirdpartyPlatform/findAllThirdpartyPlatform",
               async: false,
               data:{},
               contentType : "application/json",
               success : function(r) {
                   if (r.code === 0) {
                       var str = '';
                       r.result.map(function (item) {
                           str = str + '<option class="addOption3" value="'+ item.thirdpartyPlatformid +'">' + item.platformName + '</option>';
                       });
                       $("#thirdOs").append(str);
                       $('#thirdOs').selectpicker('refresh');
                   } else {
                       alert(r.msg);
                   }
               }
           });
       },
        displaySelect:function () {
            var optgroup = $('#siteSelect optgroup');
            if($('#siteSelect').val()){
                var siteSelectVal = $('#siteSelect').val();
                for(var i=0;i<optgroup.length;i++){
                    here:
                        for(var k=0;k<optgroup.eq(i).find('option').length;k++){
                            for(var j=0;j<siteSelectVal.length;j++){
                                if(optgroup.eq(i).find('option').eq(k).attr('value')==siteSelectVal[j]){
                                    optgroup.eq(i).find('option').eq(k).attr('disabled',false).siblings().attr('disabled','disabled')
                                    $('#siteSelect').selectpicker('refresh')
                                    break here;
                                }else{
                                    optgroup.eq(i).find('option').attr('disabled',false)
                                    $('#siteSelect').selectpicker('refresh')
                                }
                            }
                        }
                }
            }else{
                optgroup.find('option').attr('disabled',false)
                $('#siteSelect').selectpicker('refresh')
            }
        },
        changeSelect:function () {
            $('#siteSelect').on('changed.bs.select',function(e){
                // console.log($(this).val());
                vm.displaySelect();
            });
            $('#dataSource').on('changed.bs.select',function(e){
                // console.log($(this).val());
             });
            var arrName =  [];
            vm.schedule.platformId = [];
            vm.schedule.platformName = [];
            $('#timerSite').on('changed.bs.select',function(e){
                //console.log(vm.schedule.platformName)
                //console.log($(".bootstrap-select .btn").prop("title").split(","));
                arrName = [];
                $(".bootstrap-select .btn").prop("title").split(",").map(function (item) {
                    arrName.push(item);
                });
                vm.schedule.platformName = arrName;
                vm.schedule.platformId = $(this).val();
            });
        },
       getTimerAllSite:function () {
           $("#timerSite").empty();
           $.get(baseURL + "platform/findAllPlatform", function(r) {
               if (r.code === 0) {
                   var str = '';
                   r.platformList.map(function (item) {
                       str = str + '<option class="addOption" value="'+ item.platformId +'">' + item.platformName + '</option>';
                   });
                   $("#timerSite").append(str);
                   $('#timerSite').selectpicker('refresh');
                } else {
                   alert(r.msg);
               }
           });
       },
       getMenu: function(id){
           vm.cateId = id;
           $.ajax({
               type : "POST",
               url : baseURL + "baiducategory/findCategoryBindSite",
               contentType : "application/json",
               data : JSON.stringify({id:id}),
               success : function(r) {
                   if (r.code == 0) {
                       var menuList = [];
                       menuList = r.result.accountList.concat(r.result.siteList);
                       //console.log(menuList)
                       ztree = $.fn.zTree.init($("#siteType"), setting, menuList);
                       // var node = ztree.getNodeByParam("id", vm.menu.parentId);
                       // ztree.selectNode(node);
                       var arr = [];
                       var parentArr = [];
                       menuList.map(function (item) {
                           if(arr.indexOf(item.id) == -1){
                               arr.push(item.id)
                           }
                       });
                       for(var j=0;j< r.result.bindsiteIdList.length;j++){
                           for(var i=0;i<menuList.length;i++){
                               if(( r.result.bindsiteIdList[j]==menuList[i].id)&&(parentArr.indexOf(menuList[i].accountId)==-1)){
                                   parentArr.push(menuList[i].accountId);
                               }

                           }
                       }
                       //  console.log(parentArr);
                       var bindList = [];
                       bindList =  r.result.bindsiteIdList.concat(parentArr);
                       bindList.map(function (item) {
                           if(arr.indexOf(item)!= -1){
                               ztree.checkNode(ztree.getNodeByParam("id", item), true, false);
                           }
                       });
                       vm.menuTree();
                   } else {
                       alert(r.msg);
                   }
               }
           });
       },
       menuTree: function(){
           layer.open({
               type: 1,
               offset: '50px',
               skin: 'layui-layer-molv',
               title: "选择站点",
               area: ['400px', '450px'],
               shade: 0.7,
               shadeClose: false,
               content: jQuery("#siteLayer"),
               btn: ['确定', '取消'],
               btn1: function (index) {
                   var params = {
                       cateId:vm.cateId,
                       siteId:vm.checkNode
                   };
                   //console.log(params);
                   $.ajax({
                       type : "POST",
                       url : baseURL + "baiducategory/bindCateSite",
                       contentType : "application/json",
                       data : JSON.stringify(params),
                       success : function(r) {
                           if (r.code === 0) {
                               alert('操作成功', function() {
                                   $("#siteLayer").stop().hide();
                                   layer.close(index);
                                   vm.getSiteType();
                               });
                           } else {
                               alert(r.msg);
                           }
                       }
                   });


               }
           });
       },
       disabledBtn:function () {
           var userBtn1  = vm.$refs.userBtn1;
           var userBtn2  = vm.$refs.userBtn2;
           var articleBtn1 = vm.$refs.articleBtn1;
           var articleBtn2 = vm.$refs.articleBtn2;
           var domainBtn1 = vm.$refs.domainBtn1;
           userBtn1.disabled = true;
           userBtn2.disabled = true;
           articleBtn1.disabled = true;
           articleBtn2.disabled = true;
           domainBtn1.disabled = true;
           $("#userBtn1").addClass("layui-btn-disabled");
           $("#userBtn2").addClass("layui-btn-disabled");
           $("#articleBtn1").addClass("layui-btn-disabled");
           $("#articleBtn2").addClass("layui-btn-disabled");
           $("#domainBtn1").addClass("layui-btn-disabled");
       },
       saveStep1 : function() {
            var url = "platform/saveSimpleSysPlatform";
           vm.step1.siteId = $('#siteSelect').val();
           vm.step1.dataSourceId = $('#dataSource').val();
            //console.log(vm.user.platformId);
           if(checkIsBank(vm.step1.platformName) || checkIsBank(vm.step1.nickName)  || checkIsBank(vm.step1.sort) || checkIsBank(vm.step1.dataSourceId)){
                alert("全部为必填字段!");
                return false;
            }
            // vm.step1.thirdpartyPlatformId = $('#thirdOs').val();
            // vm.step1.thirdpartyChannelId = $('#thirdChannel').val();
           $.ajax({
                type : "POST",
                url : baseURL + url,
                contentType : "application/json",
                data : JSON.stringify(vm.step1),
                success : function(r) {
                     if (r.code === 0) {
                        alert('操作成功', function() {
                            vm.reload();
                            vm.param.platformId = r.result.platformId;
                            vm.showList = 'step4';
                            vm.disabledBtn();
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
       saveStep2:function () {
           var params = {
               sourceName:vm.step2.sourceName,
               dbUrl:vm.step2.dbUrl,
               username:vm.step2.username,
               password:vm.step2.password,
               dbName:vm.step2.dbName
           };
           //console.log(vm.step2.sourceName)
           if( (!checkIsBank(vm.step2.sourceName)) && (!checkIsBank(vm.step2.dbUrl)) && (!checkIsBank(vm.step2.username))
               && (!checkIsBank(vm.step2.password)) && (!checkIsBank(vm.step2.dbName))){
               $.ajax({
                   type: "post",
                   url: baseURL + "dataSource/saveDataSource",
                   data:JSON.stringify(params),
                   contentType:"application/json",
                   success: function (data) {
                       if(data.code==0){
                           alert('操作成功', function() {
                               vm.getDataSource();
                               vm.getAllSite();
                               vm.getSiteType();
                               vm.getThirdOs();
                               vm.getThirdChannel();
                               vm.showList = 'step2';
                           });
                         }else{
                           layer.msg(data.msg);
                       }
                   }
               })
           }else{
               alert("请输入完整信息");
           }
      },
     bindThirdData:function () {
           var params = {
               platformId:vm.param.platformId,
               thirdpartyPlatformId:$('#thirdOs').val(),
               thirdpartyChannelId:$('#thirdChannel').val()
           };
           if((!checkIsBank(params.thirdpartyPlatformId)) || (!checkIsBank(params.thirdpartyChannelId))){
               $.ajax({
                   type : "POST",
                   url : baseURL + "platform/bindThirdpartyPlatform",
                   contentType : "application/json",
                   data : JSON.stringify(params),
                   success : function(r) {
                       if (r.code == 0) {
                           alert('操作成功', function() {
                               vm.showList = 'step5';
                               vm.getAllPlatform();
                           });
                       } else {
                           alert(r.msg);
                       }
                   }
               });
           }else{
               alert("请输入完整信息");
           }
       },
       stepPass:function (e) {
           //console.log(e);
           vm.showList = 'step' + e;
           if(e == 3){
               vm.getDataSource();
               vm.getAllSite();
           }else if(e > 4){
               vm.getAllPlatform();
           }
       },
       saveStep3:function () {
           vm.showList = 'step3';
           vm.getDataSource();
           vm.getAllSite();
          // console.log(vm.showList);
       },
       saveStep4:function () {
           alert('平台已成功创建', function() {
              vm.param.platformId = null;
              vm.showList = 'step1';
           });
       },
       createUserTb:function () {
           var userBtn1  = vm.$refs.userBtn1;
           var userBtn2  = vm.$refs.userBtn2;
           var userBtn3  = vm.$refs.userBtn3;
          // console.log(userBtn3)
           var params = {
                  platformId:$("#platformId").val()
           };
           if(params.platformId){
               userBtn3.disabled = true;
               $("#userBtn3").addClass("layui-btn-disabled");
               $.ajax({
                   type : "POST",
                   url : baseURL + 'userPlatformOpen/saveUserTable',
                   contentType : "application/json",
                   data : JSON.stringify(params),
                   success : function(r) {
                       if (r.code === 0) {
                           alert('操作成功', function() {
                               $("#userBtn1").removeClass("layui-btn-disabled");
                               $("#userBtn2").removeClass("layui-btn-disabled");
                               userBtn1.disabled = false;
                               userBtn2.disabled = false;
                           });
                       } else {
                           userBtn3.disabled = false;
                           $("#userBtn3").removeClass("layui-btn-disabled");
                           alert(r.msg);
                       }

                   }
               });
           }
       },
       userInitData:function () {
           var userBtn1  = vm.$refs.userBtn1;
           var params = {
               platformId:$("#platformId").val()
           };
           if(params.platformId){
               $("#userBtn1").addClass("layui-btn-disabled");
               userBtn1.disabled = true;
               $.ajax({
                   type : "POST",
                   url : baseURL + 'userPlatformOpen/initiUserData',
                   contentType : "application/json",
                   data : JSON.stringify(params),
                   success : function(r) {
                       if (r.code === 0) {
                           alert('操作成功', function() {

                           });
                       } else {
                           $("#userBtn1").removeClass("layui-btn-disabled");
                           userBtn1.disabled = false;
                           alert(r.msg);
                       }
                   }
               });
           }
       },
       saveUserScheduleJob:function () {
           var userBtn2  = vm.$refs.userBtn2;
           var params = {
               platformId:$("#platformId").val()
           };
           if(params.platformId){
               $("#userBtn2").addClass("layui-btn-disabled");
               userBtn2.disabled = true;
               $.ajax({
                   type : "POST",
                   url : baseURL + 'userPlatformOpen/saveUsderTimingTask',
                   contentType : "application/json",
                   data : JSON.stringify(params),
                   success : function(r) {
                       if (r.code === 0) {
                           alert('操作成功', function() {

                           });
                       } else {
                           $("#userBtn2").removeClass("layui-btn-disabled");
                           userBtn2.disabled = false;
                           alert(r.msg);
                       }
                   }
               });
           }
       },
       createArticleTab:function () {
           var articleBtn1  = vm.$refs.articleBtn1;
           var articleBtn2  = vm.$refs.articleBtn2;
           var articleBtn0  = vm.$refs.articleBtn0;
           var params = {
               platformId:$("#artPlatform").val()
           };
           if(params.platformId){
               $("#articleBtn0").addClass("layui-btn-disabled");
               articleBtn0.disabled = true;
               $.ajax({
                   type : "POST",
                   url : baseURL + 'articleExecute/executeDynamicArticleTable',
                   contentType : "application/json",
                   data : JSON.stringify(params),
                   success : function(r) {
                       if (r.code === 0) {
                           alert('操作成功', function() {
                               $("#articleBtn1").removeClass("layui-btn-disabled");
                               $("#articleBtn2").removeClass("layui-btn-disabled");
                               articleBtn1.disabled = false;
                               articleBtn2.disabled = false;
                           });
                       } else {
                           $("#articleBtn0").removeClass("layui-btn-disabled");
                           articleBtn0.disabled = false;
                           alert(r.msg);
                       }

                   }
               });
           }
       },
       initArticleData:function () {
           var articleBtn1  = vm.$refs.articleBtn1;
           var params = {
               platformId:$("#artPlatform").val()
           };
           if(params.platformId){
               $("#articleBtn1").addClass("layui-btn-disabled");
               articleBtn1.disabled = true;
               $.ajax({
                   type : "POST",
                   url : baseURL + 'articleExecute/executeInitArticleTable',
                   contentType : "application/json",
                   data : JSON.stringify(params),
                   success : function(r) {
                       if (r.code === 0) {
                           alert('操作成功', function() {

                           });
                       } else {
                           $("#articleBtn1").removeClass("layui-btn-disabled");
                           articleBtn1.disabled = false;
                           alert(r.msg);
                       }
                   }
               });
           }
       },
       createArticleTimer:function () {
           var articleBtn2  = vm.$refs.articleBtn2;
           var params = {
               platformId:$("#artPlatform").val()
           };
           if(params.platformId){
               $("#articleBtn2").addClass("layui-btn-disabled");
               articleBtn2.disabled = true;
               $.ajax({
                   type : "POST",
                   url : baseURL + 'articleExecute/executeCreateArticleTask',
                   contentType : "application/json",
                   data : JSON.stringify(params),
                   success : function(r) {
                       if (r.code === 0) {
                           alert('操作成功', function() {

                           });
                       } else {
                           $("#articleBtn2").removeClass("layui-btn-disabled");
                           articleBtn2.disabled = false;
                           alert(r.msg);
                       }
                   }
               });
           }
       },
       createDomainTab:function () {
           var domainBtn1  = vm.$refs.domainBtn1;
           var domainBtn0  = vm.$refs.domainBtn0;
           var params = {
               platformId:$("#domainPlatform").val()
           };
           if(params.platformId){
               $("#domainBtn0").addClass("layui-btn-disabled");
               domainBtn0.disabled = true;
               $.ajax({
                   type : "POST",
                   url : baseURL + 'domainPlatformOpen/saveDomainTable',
                   contentType : "application/json",
                   data : JSON.stringify(params),
                   success : function(r) {
                       if (r.code === 0) {
                           alert('操作成功', function() {
                               domainBtn1.disabled = false;
                               $("#domainBtn1").removeClass("layui-btn-disabled");
                           });
                       } else {
                           domainBtn0.disabled = false;
                           $("#domainBtn0").removeClass("layui-btn-disabled");
                           alert(r.msg);
                       }

                   }
               });
           }
       },
       createDomainTimer:function () {
           var domainBtn1  = vm.$refs.domainBtn1;
           var params = {
               platformId:$("#domainPlatform").val()
           };
           if(params.platformId){
               $("#domainBtn1").addClass("layui-btn-disabled");
               domainBtn1.disabled = true;
               $.ajax({
                   type : "POST",
                   url : baseURL + 'domainPlatformOpen/saveDomainTask',
                   contentType : "application/json",
                   data : JSON.stringify(params),
                   success : function(r) {
                       if (r.code === 0) {
                           alert('操作成功', function() {

                           });
                       } else {
                           $("#domainBtn1").removeClass("layui-btn-disabled");
                           domainBtn1.disabled = false;
                           alert(r.msg);
                       }
                   }
               });
           }
       },
       backPreStep:function (step) {
           vm.showList = 'step'+step;
       }
    }
});
function bindSite(id) {
    vm.getMenu(id);
}
</script>
<div id="siteLayer" style="display: none;padding:10px;">
    <ul id="siteType" class="ztree"></ul>
</div>
</body>
</html>